/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.simon.mengkou.ui.view;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ouertech.android.agm.lib.base.utils.UtilDevice;
import com.simon.mengkou.R;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/3/5.
 * desc    : 收藏按钮
 */
public class CollectionButton extends LinearLayout{
    private Context mContext;
    private TextView mTvTxt;

    public CollectionButton(Context context) {
        super(context);
        init(context);
    }

    public CollectionButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CollectionButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public CollectionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        mContext  = context;
        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.CENTER);

        mTvTxt = new TextView(context);
        //mTvTxt.setCompoundDrawablePadding((int) (UtilDevice.getDevice(context).getDensity() * 2));
        mTvTxt.setGravity(Gravity.CENTER);
        mTvTxt.setText(R.string.common_collection);
        mTvTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        addView(mTvTxt, params);
    }

    /**
     * 是否关注
     * @param enabled
     */
    public void follow(boolean enabled) {
        if(enabled) {//已关注
            setBackgroundResource(R.drawable.common_bg_green_line_btn_normal);
            mTvTxt.setText(R.string.common_collection);
            mTvTxt.setTextColor(ContextCompat.getColor(mContext, R.color.res_color_accent));
            //mTvTxt.setCompoundDrawablesWithIntrinsicBounds(R.drawable.common_ic_follow, 0, 0, 0);
        } else {//关注
            setBackgroundResource(R.drawable.common_bg_red_btn_normal);
            mTvTxt.setText(R.string.common_uncollcetion);
            mTvTxt.setTextColor(ContextCompat.getColor(mContext, R.color.res_color_white));
            //mTvTxt.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }
    }
}
